<?php

namespace app\command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;


class Rule extends Command
{
    protected static $defaultName = 'hide:rules';
    protected static $defaultDescription = 'Rule';

    /**
     * @return void
     */
    protected function configure()
    {
        $this->addArgument('id', InputArgument::REQUIRED, 'Name description');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $id = $input->getArgument('id');
        $ids = explode(',', $id) ?? [];

        if (count($ids) > 0) {
            $rules = \plugin\admin\app\model\Rule::whereIn('pid', $ids)->get()->toArray();
            $subRuleIds = array_column($rules, 'id');

            \plugin\admin\app\model\Rule::whereIn('id', $ids)->update(['is_show' => 0]);
            \plugin\admin\app\model\Rule::whereIn('pid', $ids)->update(['is_show' => 0]);
            \plugin\admin\app\model\Rule::whereIn('pid', $subRuleIds)->update(['is_show' => 0]);
        }

        return self::SUCCESS;
    }

}
